package com.chain.qs.modules.biz.service;

import com.chain.qs.common.schedule.QuartzJobBean;
import com.chain.qs.common.utils.EhCacheUtils;
import org.apache.activemq.command.ActiveMQTopic;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.impl.StdScheduler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class SwitcherTaskService extends JobOperationService{

//    private final Logger logger = LoggerFactory.getLogger(this.getClass());
//
//    @Resource(name = "jmsTemplate")
//    protected JmsTemplate jmsTemplate;
//
//    @Resource(name = "commandTopicDestination")
//    protected ActiveMQTopic commandTopicDestination;
//
//    /**
//     * 任务执行时间为：班次时间+，只要任务执行就表示有超时存在
//     * @throws JobExecutionException
//     */
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        QuartzJobBean quartzJobBean = (QuartzJobBean)jobExecutionContext.getMergedJobDataMap().get("scheduleJob");
        System.out.println(quartzJobBean.getJobName()+" fbug SwitcherTashService executeInternal()...");
//        String actionStr = parseRealActionStr(quartzJobBean.getOperate());
//        if("error".equals(actionStr)){
//            logger.error("定时开关任务执行失败:"+quartzJobBean.getEquMapEquid());
//            return;
//        }
//        sendCMD(quartzJobBean.getEquMapEquid(),actionStr);
//        logger.info("定时开关任务:"+quartzJobBean.getEquMapEquid()+"-->动作:"+actionStr);
    }
//
//    private String parseRealActionStr(String original){
//        if("0".equals(original)){
//            return "shutdown";
//        }else if("1".equals(original)){
//            return "startup";
//        }
//        return "error";
//    }
//
//    private String sendCMD(String device,String cmd){
//        String flag = "false";
//        try{
//            this.jmsTemplate.convertAndSend(commandTopicDestination, device+":"+cmd);
//            flag = "true";
//        }catch (Exception e){
//            e.printStackTrace();
//        }finally {
//            return flag;
//        }
//    }
}
